package handler

import (
	"github.com/gin-gonic/gin"

	"go-papers/cache"
)

func Ping(c *gin.Context) {
	c.JSON(200, gin.H{
		"code":    0,
		"message": "ok",
		"data":    nil,
	})
}

func Info(c *gin.Context) {
	msg := "ok"
	res, err := cache.RedisServer.GetCache(c, "test", "1")
	if err != nil {
		msg = err.Error()
	}
	c.JSON(200, gin.H{
		"code":    0,
		"message": msg,
		"data":    res,
		"err":     err,
	})
}

// Cache
func Cache(c *gin.Context) {
	msg := "ok"

	key := c.Request.FormValue("key")
	res, found := cache.GoLocalCache.Get(key)
	c.JSON(200, gin.H{
		"code":    0,
		"message": msg,
		"key":     key,
		"res":     res,
		"found":   found,
	})
}
